<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 控制台主页一</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/asset/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/asset/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <img src="/my/img/background.jpg" width="100%" height="100%"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-col-md4">
            <div class="layui-card">
                <div class="layui-card-header">主题信息</div>
                <div class="layui-card-body layui-text layadmin-version">
                    <table class="layui-table">
                        <colgroup>
                            <col width="100">
                            <col>
                        </colgroup>
                        <tbody>
                        <tr>
                            <td>页面模式</td>
                            <td>iframe</td>
                        </tr>
                        <tr>
                            <td>Version</td>
                            <td>
                                <script type="text/html" template>
                                    v{{ layui.admin.v }}
                                </script>
                            </td>
                        </tr>
                        <tr>
                            <td>Layui</td>
                            <td>
                                <script type="text/html" template>
                                    v{{ layui.v }}
                                </script>
                            </td>
                        </tr>
                        <tr>
                            <td>主要特色</td>
                            <td>易上手 / 响应式 / 清爽 / 极简</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="layui-card">
                <div class="layui-card-header">效果报告</div>
                <div class="layui-card-body layadmin-takerates">
                    <div class="layui-progress" lay-showPercent="yes">
                        <h3>转化率（日同比 28% <span class="layui-edge layui-edge-top" lay-tips="增长" lay-offset="-15"></span>）</h3>
                        <div class="layui-progress-bar" lay-percent="65%"></div>
                    </div>
                    <div class="layui-progress" lay-showPercent="yes">
                        <h3>签到率（日同比 11% <span class="layui-edge layui-edge-bottom" lay-tips="下降" lay-offset="-15"></span>）</h3>
                        <div class="layui-progress-bar" lay-percent="32%"></div>
                    </div>
                </div>
            </div>

            <div class="layui-card">
                <div class="layui-card-header">系统监控</div>
                <div class="layui-card-body layadmin-takerates">
                    <div class="layui-progress" lay-showPercent="true" lay-filter="cpu">
                        <h3>CPU 使用率</h3>
                        <div class="layui-progress-bar" lay-percent="......"></div>
                    </div>
                    <div class="layui-progress" lay-showPercent="true" lay-filter="memory">
                        <h3>内存占用率</h3>
                        <div class="layui-progress-bar layui-bg-red" lay-percent="......"></div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script src="/asset/layui/layui.js"></script>
<script src="/my/fast.js"></script>
<script>
    layui.use(() => {
        let $ = layui.$
        let element = layui.element;

        // 接口地址
        // 系统监控
        let getSysInfo = UPMS_ADDRESS + '/sysMonitor/getSysInfo';
        // 前端通过ajax轮询，监听登录用户的权限和角色是否发生变化，若发生变化将自动刷新页面
        let refreshPermAndRole = GATEWAY_ADDRESS + '/refreshPermAndRole';

        let fun = () => {
            $.get(getSysInfo, rs => {
                if (rs.success) {
                    let cpuFree = rs.data.cpuInfo.free;
                    let cpuUsed = (100 - cpuFree).toFixed(2);

                    let memoryAvailable = rs.data.memory.available;
                    let memoryTotal = rs.data.memory.total;
                    let memoryUsed = (1 - (memoryAvailable / memoryTotal).toFixed(2)) * 100;

                    element.progress('cpu', cpuUsed + '%');
                    element.progress('memory', memoryUsed + '%');
                }
            });
        }
        fun();

        let fun1 = () => {
            $.get(refreshPermAndRole, rs => {
                if (rs.success) {
                    // 是否需要刷新页面的标识
                    let needRefreshPage = rs.data
                    if (needRefreshPage) {
                        parent.location.reload()
                    }
                }
            });
        }

        setInterval(() => {
            fun();
            fun1();
        }, 30000);

    });
</script>
</body>
</html>

